#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using tl = tuple < int, int, int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int mod = 998244353;
const int N = 1e5 + 10;
const int inv6 = 1ll * ((mod + 1) / 2) * ((mod + 1) / 3) % mod;

int a[N], f[N][2], n;

int upd(int x) { return x + (x >> 31 & mod); }
int s1(int x) { return 1ll * x * (x + 1) / 2 % mod; }
int s2(int x) { return 1ll * x * (x + 1) % mod * (2 * x + 1) % mod * inv6 % mod; }

int calc(int x, int y) {
	memset(f, 0, sizeof f);
	f[1][x] = 1; 
	rep(i, 1, n) {
		int to = i % n + 1;
		f[to][0] = upd(f[to][0] + 1ll * f[i][1] * (a[i] - y + 1) % mod - mod);
		f[to][0] = upd(f[to][0] + 1ll * f[i][0] * s1(a[i] - y) % mod - mod);
		f[to][1] = upd(f[to][1] + 1ll * f[i][0] * upd(1ll * a[i] * s1(a[i]) % mod - s2(a[i])) % mod - mod);
		f[to][1] = upd(f[to][1] + 1ll * f[i][1] * s1(a[i]) % mod - mod);
	} return f[1][x];
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
	n = in; rep(i, 1, n) a[i] = in;
	int ans = upd(calc(1, 0) + calc(0, 0) - mod);
	ans = upd(ans - calc(1, 1));
	ans = upd(ans - calc(0, 1));
	printf("%d\n", ans);
	return 0;
}
